﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using forever.Gobal;

namespace gencode.UI
{
    public partial class ucGenerateBySproc : UserControl
    {
        private string db;
        private string namesproc;
        List<DataTable> dtParamester = new List<DataTable>();
        DataTable SprocNameList = new DataTable();
        List<string> descrestionSproc = new List<string>();
        List<string> returnSproc = new List<string>();
        List<string> namemethod = new List<string>();
        //SelectSprocParamesterNames
        public ucGenerateBySproc(string db, string namesproc)
        {
            InitializeComponent();
            this.db = db;
            this.namesproc = namesproc;
            init();
        }
        void init()
        {
            txtBLL.Text = ConfigurationSettings.AppSettings["modifiersBLL"];
            txtDAL.Text = ConfigurationSettings.AppSettings["modifiersDAL"];
            txtView.Text = ConfigurationSettings.AppSettings["modifiersView"];
            txtBusinessLogicLayer.Text = ConfigurationSettings.AppSettings["BusinessLogicLayer"];
            txtDataAccessLayer.Text = ConfigurationSettings.AppSettings["DataAccessLayer"];
            txtPresentationLayer.Text = ConfigurationSettings.AppSettings["PresentationLayer"];
            txtDataObjectLayer.Text = ConfigurationSettings.AppSettings["DataObjectLayer"];
            txtUserClass.Text = ConfigurationSettings.AppSettings["user"];
            txtNamespaceParent.Text = db;
            txtnamemethod.Text = namesproc;
            chkInfoClass.Checked = true;
            cbbTypeReturn.SelectedIndex = 0;
            txtnamemethod.Text = namesproc;
            txtDescription.Text = namesproc;
            //
            UpdateComboBoxSampleData();
            //
            GenDefaultText();

        }
        void UpdateComboBoxSampleData()
        {
            DataTable dt = Gobal.SelectTableNames(db);
            classcommon.Properties.Items.BeginUpdate();
            try
            {
                classcommon.Properties.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    classcommon.Properties.Items.Add(dt.Rows[i]["TABLE_NAME"]);
                }
            }
            finally
            {
                classcommon.Properties.Items.EndUpdate();
            }
            if (classcommon.Properties.Items.Count > 0)
                classcommon.SelectedIndex = 0;
        }
        void GenDefaultText()
        {
            returnSproc.Clear();
            namemethod.Clear();
            SprocNameList = new DataTable();
            dtParamester.Clear();
            descrestionSproc.Clear();
            switch (cbbLanguages.SelectedItem.ToString())
            {
                case "C# Three layer":
                    returnSproc.Add(cbbTypeReturn.Text);
                    namemethod.Add(txtnamemethod.Text);
                    SprocNameList = Gobal.SelectSprocNameInfo(db, namesproc);
                    dtParamester.Add(Gobal.SelectSprocParamesterNames(db, namesproc));
                    descrestionSproc.Add(txtDescription.Text);
                    gencodeSharp gen = new gencodeSharp(chkInfoClass.Checked,
                         comboBoxEdit1.Text, txtUserClass.Text,
                        "", txtView.Text, txtBLL.Text,
                        txtDAL.Text, txtDataAccessLayer.Text, txtDataObjectLayer.Text,
                        txtBusinessLogicLayer.Text, txtPresentationLayer.Text,
                        txtNamespaceParent.Text, dtParamester, SprocNameList, db,
                        cbbCnData.Text, returnSproc, descrestionSproc, namemethod, classcommon.Text);
                    List<string> listStr = gen.GenerateListMethodBySproc();
                    txtVIEWS.Text = listStr[0];
                    txtDALS.Text = listStr[1];
                    txtBLLS.Text = listStr[2];
                    txtSPROCS.Text = listStr[3];
                    break;
            }
        }
        private void bntGenerate_Click(object sender, EventArgs e)
        {
            GenDefaultText();
        }

        private void bntChangeDefault_Click(object sender, EventArgs e)
        {
            init();
        }

        private void txtDelete_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

    }
}
